using JT808Protocol.Common;
using System;
using System.Text.Json.Serialization;

namespace JT808Protocol.Models.BodyParserStrategy.Location.LocationAddition
{
    /// <summary>
    /// 存储故障
    /// </summary>
    public class LaStorageFailure_0x17 : ILocationAddition
    {
        /// <summary>
        /// 故障状态，0-11 表示 1 - 12 个主存储器，12-15 表示 4 个灾备存储器
        /// </summary>
        [JsonPropertyName("故障状态")] public ushort AlarmStatus { get; set; }

        public override ILocationAddition ReadEntity(ReadOnlySpan<byte> source, int startIndex)
        {
            DataLength = (byte)(source[startIndex + 1] + 2);
            if (DataLength != 2 + 2)
            {
                //Logger.Warn($"位置上报附加存储故障长度错误，data:{BitConverter.ToString(source, startIndex, source[startIndex + 1] + 2)}");
                return null;
            }
            AlarmStatus = ParseHelper.Uint16(ref source, startIndex + 2);

            return this;
        }
    }
}